const fs = require('fs')

//读取三个文件，将他们的内容拼接打印到控制台

//旧方法 回调地狱
// fs.readFile('./resources/为学.md', (err, data1)=>{
//     fs.readFile('./resources/为学2.md', (err, data2)=>{
//         fs.readFile('./resources/为学3.md', (err, data3)=>{
//             let result = data1 + '\n' + data2 + '\n' + data3
//             console.log(result)
//         })
//     })
// })

//使用promise
const p = new Promise((resolve, reject)=>{
    fs.readFile('./resources/为学.md', (err, data)=>{
        resolve(data)
    })
}) 

p.then(data=>{
    return new Promise((resolve, reject)=>{
        fs.readFile('./resources/为学2.md', (err, data2)=>{
            resolve([data,  data2])
        })
    })
}).then(datas=>{
    return new Promise((resolve, reject)=>{
        fs.readFile('./resources/为学3.md', (err, data3)=>{
            resolve([...datas,  data3])
        })
    })
}).then(datas=>{
    let result = datas[0] + '\n' + datas[1] + '\n' + datas[2]
    console.log(result)
})